package com.sr.examination.exam.exercise.category;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;

import com.sr.examination.R;
import com.tl.commonlibrary.ui.beans.ExerciseBean;
import com.tl.commonlibrary.ui.beans.ExerciseListBean;
import com.tl.commonlibrary.ui.beans.ExerciseOption;

import java.util.List;

/**
 * Created by jiangzhongshan on 18/2/3.
 * 多选
 */

public class MultipleChoiceFragment extends ChoiceFragment {
    public static MultipleChoiceFragment newInstance(ExerciseBean exerciseBean, int examMethod) {
        MultipleChoiceFragment fragment = new MultipleChoiceFragment();
        fragment.setExerciseBean(exerciseBean);
        fragment.setExamMethod(examMethod);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        exerciseType = ExerciseBean.TYPE_MULTIPLE_CHOOSE;
        super.onCreateView(inflater, container, savedInstanceState);
        choiceListView.setChoiceMode(exerciseBean.isAnswered() ? AbsListView.CHOICE_MODE_NONE : AbsListView.CHOICE_MODE_MULTIPLE);
        setDescription(getString(R.string.exercise_multiple_title_content, exerciseBean.getScore(), exerciseBean.getItemQuest()));
        return root;
    }

    @Override
    protected void initOption() {
        String userAnswer = exerciseBean.getUserAnswer();
        if (!TextUtils.isEmpty(userAnswer)) {
            String[] answers = userAnswer.split(",");
            List<ExerciseOption> options = exerciseBean.getOptions();
            exerciseBean.setAnswered(true);
            if (options != null && !options.isEmpty()) {
                ExerciseOption tempOption = null;
                for (int i = 0; i < answers.length; i++) {
                    if (!TextUtils.isEmpty(answers[i])) {
                        for (int j = 0; j < options.size(); j++) {
                            tempOption = options.get(j);
                            if (answers[i].equals(tempOption.getId())) {
                                tempOption.setChecked(true);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void lazyLoad() {
        super.lazyLoad();
    }

    @Override
    protected void onExerciseAnalysisModeCalled() {
        super.onExerciseAnalysisModeCalled();
    }

    @Override
    protected void onExerciseAnsweringModeCalled() {
        super.onExerciseAnsweringModeCalled();
    }

    @Override
    public void saveExerciseInstanceState() {
        super.saveExerciseInstanceState();
    }

    @Override
    protected void onClickOption(List<ExerciseOption> options) {

    }


    @Override
    public void onClick(View v) {

    }
}
